package com.boc.langxiang.presenter.shop;

import com.boc.langxiang.contract.shop.ProductCustomizeContract;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.ProductCustomizeRequest;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/12/26.
 */

public class ProductCustomizePresenter implements ProductCustomizeContract, ProductCustomizeContract.Presenter {
    private View mView;

    public ProductCustomizePresenter(View view) {
        this.mView = view;
    }

    @Override
    public void customize(ProductCustomizeRequest request) {
        mView.showLoading();
        mService.productCustomize(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse>(mView) {
                    @Override
                    public void onSuccess(BaseResponse response) {
                        mView.hideLoading();
                        mView.onSuccess();
                    }
                });
    }
}
